<?php
	/*
		Plugin Name: Social Hub
		Plugin URI: http://www.colegeissinger.com/social-hub/
		Description: Allows a user to set social links or twitter feeds/facebook like box through widgetized areas or shortcodes
		Version: 1.0
		Author: Cole Geissinger
		Author URI: http://www.colegeissinger.com/
		License: GPL3
	*/
	
	/*
		Copyright (C) 2011 Cole Geissinger
   		
    	This program is free software: you can redistribute it and/or modify
    	it under the terms of the GNU General Public License as published by
    	the Free Software Foundation, either version 3 of the License, or
    	(at your option) any later version.
   		
    	This program is distributed in the hope that it will be useful,
    	but WITHOUT ANY WARRANTY; without even the implied warranty of
    	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    	GNU General Public License for more details.
   		
    	You should have received a copy of the GNU General Public License
    	along with this program.  If not, see <http://www.gnu.org/licenses/>. 
	*/
	
	
	//**============================================================**//
	//                     Version Check                              //
	//    Check that the current version running is 2.9 or higher     //
	//**============================================================**//
	if(version_compare(get_bloginfo('version'), '2.9', '<')) {
		exit('Social Hub requires WordPress version 2.9 or higher. Please <a href="http://codex.wordpress.org/Upgrading_WordPress">update WordPress</a> to install.');
	}
	
	
	//**************************************************
	//**Purpose: feed the needed CSS stylesheet to style our buttons and widgets
	if(!is_admin()) {
		wp_enqueue_style('sh-styles', plugins_url('/_css/style.css', __FILE__), '1.0', 'screen');
	}
	
	
	//**************************************************
	//**Function: sh_admin_styles()
	//**Purpose: allows us to customize our custom admin page
	function sh_admin_head() {
		wp_enqueue_style('sh-admin', plugins_url('/_css/admin.css', __FILE__), '1.0', 'screen');
		wp_enqueue_style('sh-colorpicker', plugins_url('/_css/colorpicker.css', __FILE__), '1.0', 'screen');
		wp_enqueue_script('jquery');
		wp_enqueue_script('sh-admin', plugins_url('/_scripts/admin.js', __FILE__), array('jquery'), '1.0', true);
		wp_enqueue_script('sh-colorpicker', plugins_url('/_scripts/colorpicker.js', __FILE__), array('jquery'), '23.05.2009', true);
	}
	add_action('admin_print_styles', 'sh_admin_head');
	
	
	//******************************
	//**Function: sh_print_styles()
	//**Purpose: prints our stylesheet to the front-end
	function sh_print_styles() {
		if(!is_admin()) {
			wp_enqueue_style('sh-styles', plugins_url('/_css/style.css', __FILE__), '1.0', 'screen');
		}
	}
	add_action('wp_print_styles', 'sh_print_styles');
	
	
	//******************************
	//**Purpose: Load some needed external PHP scripts
	include_once('_includes/sh-wp-widgets.php'); //load our WordPress Widgets
	
	
	//**************************************************
	//**Function: sh_widget_init()
	//**Purpose: registers the social hub widgets
	function sh_widget_init() {
		register_sidebar('sh_widget_links');
	}
	add_action('plugins_loaded', 'sh_widget_init');
	
	
	//**************************************************
	//**Function: sh_widget_links()
	//**Purpose: creates a function for our widget of social media buttons/links
	function sh_register_widgets() {
		register_widget('sh_links');
	}
	add_action('widget_init', 'sh_register_widgets');
	
	
	//**************************************************
	//**Function: sh_widget_links()
	//**Purpose: creates a function for our widget of social media buttons/links
	function sh_links() { 
		include('_includes/sh_global_variables.php'); //load in our variables
		//retrieve the database information ?>
		<ul id="social-hub">
		
			<?php //check if the facebook link is enabled
			if($facebook_get_values['url-enabled'] == 'enabled') :?>
				<li id="sh-facebook"><a href="<?php echo $facebook_get_values['url']; ?>" target="_blank" title="Like us on Facebook to get exclusive offers">Facebook</a> <span class="social-description"><?php echo $facebook_get_values['description']; ?>Like us on Facebook to get exclusive offers</span></li>
			<?php endif; //close $facebook_links_enabled IF STATEMENT
			
			
			//check if the twitter link is enabled
			if($twitter_get_values['url-enabled'] == 'enabled') : ?>
				<li id="sh-twitter"><a href="<?php echo $twitter_get_values['url']; ?>" target="_blank" title="Get the latest news and quick tips">Twitter</a> <span class="social-description">Get the latest news and quick tips</span></li>
			<?php endif; //close $twitter_links_enabled IF STATEMENT
			
			
			//check if the linkedin link is enabled
			if($linkedin_get_values['url-enabled'] == 'enabled') : ?>
				<li id="sh-linkedin"><a href="<?php echo $linkedin_get_values['url']; ?>" target="_blank" title="View our profile on LinkedIn">LinkedIn</a> <span class="social-description">View our profile on LinkedIn</span></li>
			<?php endif; //close $linkedin_links_enabled IF STATEMENT
			
			
			//check if the youtube link is enabled
			if($youtube_get_values['url-enabled'] == 'enabled') : ?>
				<li id="sh-youtube"><a href="<?php echo $youtube_get_values['url']; ?>" target="_blank" title="Subscribe to our YouTube channel">YouTube</a> <span class="description">Subscribe to our YouTube channel</span></li>
			<?php endif; //close $youtube_links_enabled IF STATEMENT
			
			
			//check if the google link is enabled
			if($google_get_values['url-enabled'] == 'enabled') : ?>
				<li id="sh-google"><a href="<?php echo $google_get_values['url']; ?>" target="_blank" title="Read our reviews on Google">Google</a> <span class="description">Read our reviews on Google</span></li>
			<?php endif; //close $google_links_enabled IF STATEMENT
			
			//check if the yelp link is enabled
			if($yelp_get_values['url-enabled'] == 'enabled') : ?>
				<li id="sh-yelp"><a href="<?php echo $yelp_get_values['url']; ?>" target="_blank" title="Read our reveiews on Yelp">Yelp</a> <span class="description">Read our reviews on Yelp</span></li>
			<?php endif; //close $yelp_links_enabled IF STATEMENT ?>
			
		</ul> 
	<?php }
	
	
	//**************************************************
	//**Function: sh_facebook_widget()
	//**Purpose: creates a list of social media buttons and facebook like box and twitter feed
	function sh_facebook_widget() {
		include('_includes/sh_global_variables.php'); //load in our variables
		
		
		
		if($facebook_get_values['widget-enabled'] == 'enabled') : ?>
			<div id="fb-root"></div>
			<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
			<fb:like-box href="<?php echo $facebook_get_values['widget-url']; ?>" width="<?php echo $facebook_get_values['widget-width']; ?>" show_faces="<?php if($facebook_get_values['widget-faces'] == 'enabled') { echo 'true'; } else { echo 'false'; } ?>" border_color="<?php echo $facebook_get_values['widget-border-color']; ?>" stream="<?php if($facebook_get_values['widget-stream'] == 'enabled') { echo 'true'; } else { echo 'false'; } ?>" header="<?php if($facebook_get_values['widget-header'] == 'enabled') { echo 'true'; } else { echo 'false'; } ?>"></fb:like-box>
		<?php else : echo 'You must enable the Facebook Widget to use it!'; endif; //close IF STATEMENT
	} //close sh_facebook_widget()
	
	
	//**************************************************
	//**Function: sh_twitter_widget()
	//**Purpose: creates a list of social media buttons and facebook like box and twitter feed
	function sh_twitter_widget() {
		include('_includes/sh_global_variables.php');
		
		if($twitter_get_values['widget-enabled'] == 'enabled') { ?>
			<div id="sh-twitter-widget">
				<script src="http://widgets.twimg.com/j/2/widget.js" type="text/javascript"></script>
				<script type="text/javascript">
					new TWTR.Widget({
						version: 2,
						type: 'profile',
						rpp: 3,
						interval: 6000,
						width: <?php echo $twitter_get_values['widget-width']; ?>,
						height: <?php echo $twitter_get_values['widget-height']; ?>,
						theme: {
							shell: {
								background: '#<?php echo $twitter_get_values['widget-shell-bg']; ?>',
								color: '#<?php echo $twitter_get_values['widget-shell-txtcolor']; ?>'
							}, tweets: {
								background: '#<?php echo $twitter_get_values['widget-tweet-bg']; ?>',
								color: '#<?php echo $twitter_get_values['widget-tweet-color']; ?>',
								links: '#<?php echo $twitter_get_values['widget-tweet-linkcolor']; ?>'
							}
						}, features: {
							scrollbar: false,
							loop: false,
							live: false,
							hashtags: true,
							timestamp: true,
							avatars: false,
							behavior: 'all'
						}
					}).render().setUser('<?php echo $twitter_get_values['widget-url']; ?>').start();
				</script>
			</div>
		<?php } else { echo 'Twitter Feed Widget is not enabled!'; } //close $twitter_widget_enabled IF STATEMENT
	} //close sh_twitter_widget()
	
	
	//**************************************************
	//**Function: sh_admin()
	//**Purpose: includes our social hub admin functions
	function sh_admin() {
		include('_includes/sh_admin.php');
	}
	
	
	//**************************************************
	//**Function: sh_admin_options()
	//**Purpose: Adds an options tab to the admin area along with setting the functions for the widgets and links
	function sh_admin_options() {
		add_options_page('Social Hub Functions', 'Social Hub', 1, 'social-hub', 'sh_admin');
	}
	add_action('admin_menu', 'sh_admin_options');
	

?>